//
//  AIPicVipAlertView.m
//  Mia
//
//  Created by Vill on 2024/2/4.
//

#import "AIPicVipAlertView.h"

@interface AIPicVipAlertView ()

@property (nonatomic, strong) UIView *containView;
@property (nonatomic, strong) UIButton *closeBtn;
@property (nonatomic, strong) UIButton *confirmBtn;   //确认
@property (nonatomic, strong) UILabel *alertTitle;    //标题
@property (nonatomic, strong) UILabel *detailLbl;     //详情

@end

@implementation AIPicVipAlertView

- (instancetype)init{
    self = [super init];
    if (self) {
        self.contentView.backgroundColor = UIColor.clearColor;
        [self.contentView addSubview:self.containView];
        
        [self.contentView addSubview:self.closeBtn];
        [self.contentView addSubview:self.confirmBtn];
        [self.contentView addSubview:self.alertTitle];
        
        [self.containView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.trailing.top.mas_equalTo(self.contentView);
            make.height.mas_equalTo(PTW(275));
            make.bottom.mas_equalTo(self.contentView);
        }];
        [self.closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(PTW(34));
            make.top.mas_equalTo(self.contentView).mas_offset(PTW(15));
            make.trailing.mas_equalTo(self.contentView).mas_offset(-PTW(15));
        }];
        [self.confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.mas_equalTo(self.contentView).mas_offset(PTW(15));
            make.trailing.mas_equalTo(self.contentView).mas_offset(-PTW(15));
            make.bottom.mas_equalTo(self.contentView).mas_offset(-PTW(30));
            make.height.mas_equalTo(PTW(60));
        }];
        [self.alertTitle mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.contentView).mas_offset(PTW(30));
            make.centerX.mas_equalTo(self.contentView);
        }];
        [self.contentView addSubview:self.detailLbl];
        [self.detailLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self.contentView);
            make.top.mas_equalTo(self.alertTitle.mas_bottom).mas_offset(PTW(40));
        }];
    }
    return self;
}

// 容器
- (UIView *)containView{
    if(!_containView){
        _containView = [UIView new];
        [_containView setGradientBackgroundWithColors:@[[UIColor colorHex:@"#FDADBC" alpha:1],[UIColor colorHex:@"#834CA8" alpha:1]] locations:@[@0,@1] startPoint:CGPointMake(0,0) endPoint:CGPointMake(0, 1)];
    }
    return _containView;
}

-(UIButton *)closeBtn{
    if(!_closeBtn){
        _closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_closeBtn setImage:KImaged(@"ai_main_close") forState:UIControlStateNormal];
        [_closeBtn addTarget:self action:@selector(closeAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _closeBtn;
}

- (UIButton *)confirmBtn{
    if(!_confirmBtn){
        _confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_confirmBtn setTitle:@"Confirm" forState:UIControlStateNormal];
        [_confirmBtn setTitleColor:[UIColor colorHex:@"#5C5C5C"] forState:UIControlStateNormal];
        _confirmBtn.titleLabel.font = [UIFont fontWithWeight:MTBold size:PTW(15)];
        _confirmBtn.backgroundColor = [UIColor whiteColor];
        _confirmBtn.layer.cornerRadius = PTW(30);
        _confirmBtn.layer.shadowColor = [UIColor colorHex:@"#FFFFFF" alpha:0.68].CGColor;
        _confirmBtn.layer.shadowOffset = CGSizeMake(0,0);
        _confirmBtn.layer.shadowOpacity = 1;
        _confirmBtn.layer.shadowRadius = 8;
        [_confirmBtn addTarget:self action:@selector(confirmAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _confirmBtn;
}

- (UILabel *)alertTitle{
    if(!_alertTitle){
        _alertTitle = [UILabel new];
        _alertTitle.textColor = [UIColor whiteColor];
        _alertTitle.textAlignment = NSTextAlignmentCenter;
        _alertTitle.numberOfLines = 0;
        NSMutableAttributedString *contentAtt = [[NSMutableAttributedString alloc] initWithString:@"Unlock" attributes:@{NSFontAttributeName : [UIFont fontWithWeight:MTBold size:PTW(27)]}];
        NSTextAttachment *imageMent = [[NSTextAttachment alloc] init];
        imageMent.image = KImaged(@"ai_vip_plus");
        imageMent.bounds = CGRectMake(0, -PTW(4), PTW(84.5), PTW(28.5));
        NSAttributedString *imageAtt = [NSAttributedString attributedStringWithAttachment:imageMent];
        [contentAtt appendAttributedString:imageAtt];
        _alertTitle.attributedText = contentAtt;
    }
    return _alertTitle;
}

- (UILabel *)detailLbl{
    if(!_detailLbl){
        _detailLbl = [UILabel new];
        _detailLbl.textColor = [UIColor colorHex:@"#FFFFFF"];
        _detailLbl.font = [UIFont fontWithWeight:MTBold size:PTW(17)];
        _detailLbl.textAlignment = NSTextAlignmentCenter;
        _detailLbl.numberOfLines = 0;
        _detailLbl.text = @"You need to activate Plus to \npost pictures";
    }
    return _detailLbl;
}


// 确认
-(void)confirmAction{
    [self dismiss];
    if (self.certainBlock){
        self.certainBlock();
    }
}

// 关闭
-(void)closeAction{
    [self dismiss];
}

@end
